package com.yanqu.road.server.cmd.activity.uniongroup;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.union.UnionActivityGroupProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.UnionActivityGroupModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_UNION_ACTIVITY_GROUP_CLIENT_GET_ABLE,desc = "客户端请求获取某个活动是否有资格")
public class UnionActivityGroupGetAbleCmd extends AbstractCommand {

    private int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionActivityGroupProto.UnionActivityGroupClientGetAbleReqMsg reqMsg = UnionActivityGroupProto.UnionActivityGroupClientGetAbleReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(UnionActivityGroupModule.class).clientGetAble(activityId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            UnionActivityGroupProto.UnionActivityGroupClientGetAbleRespMsg.Builder builder = UnionActivityGroupProto.UnionActivityGroupClientGetAbleRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_UNION_ACTIVITY_GROUP_CLIENT_GET_ABLE, builder);
        }
    }
}
